package com.ruoyi.third.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.third.domain.ThirdPlatform;
import com.ruoyi.third.service.IThirdPlatformService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 接入平台Controller
 * 
 * @author yepanpan
 * @date 2025-02-06
 */
@RestController
@RequestMapping("/third/platform")
public class ThirdPlatformController extends BaseController
{
    @Autowired
    private IThirdPlatformService thirdPlatformService;

    /**
     * 查询接入平台列表
     */
    @GetMapping("/select")
    public TableDataInfo select(ThirdPlatform thirdPlatform)
    {
        List<ThirdPlatform> list = thirdPlatformService.selectThirdPlatformList(thirdPlatform);
        return getDataTable(list);
    }

    /**
     * 查询接入平台列表
     */
    @PreAuthorize("@ss.hasPermi('third:platform:list')")
    @GetMapping("/list")
    public TableDataInfo list(ThirdPlatform thirdPlatform)
    {
        startPage();
        List<ThirdPlatform> list = thirdPlatformService.selectThirdPlatformList(thirdPlatform);
        return getDataTable(list);
    }

    /**
     * 导出接入平台列表
     */
    @PreAuthorize("@ss.hasPermi('third:platform:export')")
    @Log(title = "接入平台", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ThirdPlatform thirdPlatform)
    {
        List<ThirdPlatform> list = thirdPlatformService.selectThirdPlatformList(thirdPlatform);
        ExcelUtil<ThirdPlatform> util = new ExcelUtil<ThirdPlatform>(ThirdPlatform.class);
        util.exportExcel(response, list, "接入平台数据");
    }


    /**
     * 获取接入平台详细信息
     */
    @PreAuthorize("@ss.hasPermi('third:platform:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(thirdPlatformService.selectThirdPlatformById(id));
    }

    /**
     * 新增接入平台
     */
    @PreAuthorize("@ss.hasPermi('third:platform:add')")
    @Log(title = "接入平台", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody ThirdPlatform thirdPlatform)
    {
        return toAjax(thirdPlatformService.insertThirdPlatform(thirdPlatform));
    }

    /**
     * 修改接入平台
     */
    @PreAuthorize("@ss.hasPermi('third:platform:edit')")
    @Log(title = "接入平台", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody ThirdPlatform thirdPlatform)
    {
        return toAjax(thirdPlatformService.updateThirdPlatform(thirdPlatform));
    }

    /**
     * 删除接入平台
     */
    @PreAuthorize("@ss.hasPermi('third:platform:remove')")
    @Log(title = "接入平台", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(thirdPlatformService.deleteThirdPlatformByIds(ids));
    }


    /**
     * 启动
     */
    @PreAuthorize("@ss.hasPermi('third:platform:list')")
    @GetMapping(value = "/start/{id}")
    public AjaxResult start(@PathVariable("id") Long id)
    {
        return success(thirdPlatformService.triggerThirdPlatform("start", id));
    }

    /**
     * 停止
     */
    @PreAuthorize("@ss.hasPermi('third:platform:list')")
    @GetMapping(value = "/stop/{id}")
    public AjaxResult stop(@PathVariable("id") Long id)
    {
        return success(thirdPlatformService.triggerThirdPlatform("stop", id));
    }
}
